


export function initComponentMapInPage(componentMap, allPages){
  _.forEach(allPages, (page) => {
    initComponentMap(componentMap, page);
  })
}

function initComponentMap(componentMap, pageOrGroupComponent){
  _.forEach(pageOrGroupComponent.components, (componentData) => {
    componentMap[componentData.id] = componentData;
    if(componentData.components && componentData.components.length > 0){
      initComponentMap(componentMap, componentData);
    }
  })
}

export function getComponentDataInAllById(searchId, allPages){
  for(let j = 0, len = allPages.length; j < len ; j++){
    let page = allPages[j];
    let componentData = searchComponentDataById(searchId, page);
    if(componentData){
      return componentData;
    }
  }
  return null;
}

export function searchComponentDataById(searchId, pageOrGroupComponent){
  let components = pageOrGroupComponent.components;
  let len = components.length;
  let componentData_
  for(let i = 0; i < len; i++){
    componentData_ = components[i]
    if(componentData_.id == searchId){
      return componentData_
    }else{
      if(componentData_.components && componentData_.components.length > 0){
        let compData = searchComponentDataById(searchId, componentData_)
        if(compData){
          return compData;
        }
      }
    }
  }
  return null
}